﻿#include "mainwindow.h"

#include <QLabel>
#include <QTextEdit>
#include <QDateTimeEdit>
#include <QCheckBox>
#include <QLineEdit>
#include <QPushButton>
#include <QTableView>
#include <QStandardItemModel>
#include <QSpacerItem>
#include <QHeaderView>

#include <QDebug>
#include "logqueue.h"

MainWindow::MainWindow(const QList<bool> &rights, QWidget *parent)
    : QMainWindow(parent)
{
    this->resize(800, 600);
    this->setWindowIcon(QIcon(":/new/prefix1/编辑信息表.png"));

    auto widget = new QWidget(this);
    widget->setObjectName("centralWidget");
    this->setCentralWidget(widget);

    QVBoxLayout *layoutMain = new QVBoxLayout(widget);
    layoutMain->setObjectName("layoutMain");
    layoutMain->setContentsMargins(0, 0, 0, 0);

    auto labTitle = new QLabel("软件运维", widget);
    labTitle->setObjectName("labTitle");
    labTitle->setAlignment(Qt::AlignCenter);
    layoutMain->addWidget(labTitle);

    QFont font;
    font.setPointSize(16);
    font.setBold(true);
    labTitle->setFont(font);

    m_tabLogWidget = new QTabWidget(widget);
    m_tabLogWidget->setStyleSheet("QTabWidget::tab-bar{alignment: center;}");
    layoutMain->addWidget(m_tabLogWidget, 1);

    // 根据权限, 初始化控件并展示
    if (rights.size() >= 5 && rights.at(4)) {
        m_alarmTab = new LogTabPanel(m_tabLogWidget, LogQueue::LogType::LogType_Alarm);
        m_tabLogWidget->addTab(m_alarmTab, tr("告警日志"));
    }
    if (rights.size() >= 1 && rights.at(0)) {
        m_softRunTab = new LogTabPanel(m_tabLogWidget, LogQueue::LogType::LogType_SoftRun);
        m_tabLogWidget->addTab(m_softRunTab, tr("软件启动日志"));
    }
    if (rights.size() >= 2 && rights.at(1)) {
        m_deviceTab = new LogTabPanel(m_tabLogWidget, LogQueue::LogType::LogType_Device);
        m_tabLogWidget->addTab(m_deviceTab, tr("设备启动日志"));
    }
    if (rights.size() >= 3 && rights.at(2)) {
        m_userTab = new LogTabPanel(m_tabLogWidget, LogQueue::LogType::LogType_User);
        m_tabLogWidget->addTab(m_userTab, tr("用户操作日志"));
    }
    if (rights.size() >= 4 && rights.at(3)) {
        m_bgTraceTab = new LogTabPanel(m_tabLogWidget, LogQueue::LogType::LogType_BGTrace);
        m_tabLogWidget->addTab(m_bgTraceTab, tr("背景迹线日志"));
    }
}

MainWindow::~MainWindow()
{
}
